const enterpriseVue = new Vue({
  el: '#app',
  data() {
    return {
      form: {//提交的表单
        Enterprise_Info_SerialNumber: '',//主键
        Picture_URL: "https://fuss10.elemecdn.com/e/5d/4a731a90594a4af544c0c25941171jpeg.jpeg",
        Enterprise_Name: "",//企业名称
        Industry_SubCategory_SerialNumber: "101000000000001",
        Industry_Category_SerialNumber: "100000000000001",
        Enterprise_Address: '',//企业注册地址
        Postal_Code: '',//邮政编号
        Tax_Number: '',//营业执照注册号
        Tax_Registration_Number: '',//税务登记证号
        Organization_Code_Certificate_Number: '',//组织机构代码证号
        Enterprise_Phone: '',//企业电话
        Enterprise_Contacts: '',//企业联系人
        Enterprise_Contacts_Mobile: '',//企业手机号
        E_Mail: '',//电子邮箱
        Children: {
          enterprise_legal_person: [{
            Enterprise_Legal_Person_SerialNumber: "",
            Enterprise_Info_SerialNumoer: "",
            Legal_Person: '',//法人姓名
            ID_Number: '',//法人身份证号
            Mobile: '',//法人手机号
          }],
          enterprise_account: [{
            Enterprise_Account_SerialNumber: "",
            Enterprise_Info_SerialNumoer: "",
            Bank_Name: '',//开户行
            Account_Number: '',//银行账号
          }]
        }
      },
      loading: false,
      form1: {
        Enterprise_Account_SerialNumber: "",
        Enterprise_Info_SerialNumber: $.cookie("enterprise"),
        Account_Name: "",
        Account_Number: "",
        Bank_Name: "",
      },
      label: " ",
      sales_order_logistics: [{
        Sales_Order_Logistics_SerialNumber: '', //主键
        Sales_Order_SerialNumber: '啊啊啊',   //账户名称
        LogisticsNumbers: '155161616',  //开户银行
        LogisticsCode: '625494899546',  //银行账户
      },
      {
        Sales_Order_Logistics_SerialNumber: '', //主键
        Sales_Order_SerialNumber: '啵啵啵',   //账户名称
        LogisticsNumbers: '155161616',  //开户银行
        LogisticsCode: '625494899546',  //银行账户
      }
      ],
      OddNumbers: false, // 控制驳回弹窗的显示与隐藏
      rejectReason: '', // 驳回理由
      loading: false,
      dialogVisible: false,
      dialogImageUrl: '',
    }
  },
  mounted() {
    const Enterprise_Info_SerialNumber = sessionStorage.getItem('Enterprise_Info_SerialNumber')
      this.getEnterpriseData(Enterprise_Info_SerialNumber)
  },
  computed: {

  },
  methods: {
    // 新增银行账户
    add_sales_order_logistics() {
      // var enterprise_account = {
      //   Account_Name:"",
      //   Account_Number:"",
      //   Bank_Name:"",
      //   Enterprise_Info_SerialNumber:"",
      // }
      var _this = this
      console.log(this.form1)
      // $.ajax({
      //   url: DomainName + '/getAddAction',
      //   type: 'POST',
      //   data:{ Data: JSON.stringify({ enterprise_account: [_this.form1] })},
      //   success: function (result) {
      //     console.log(result)
      //   },
      //   error: function (params) {
      //     console.log(params);
      //   },
      // })
    },
    remove_sales_order_logistics() {
      if (this.sales_order_logistics.length > 1) {
        this.sales_order_logistics.pop()
      } else {
        this.$message({
          message: '不能在删除了',
          type: 'warning'
        })
      }
    },
    // 清空银行信息
    qing_sales_order_logistics() {
      this.sales_order_logistics = [{
        Sales_Order_Logistics_SerialNumber: '',
        Sales_Order_SerialNumber: '',
        LogisticsNumbers: '',
        LogisticsCode: '',
        Quantity: '',
        checked: false
      }]
    },
    getEnterpriseData(Enterprise_Info_SerialNumber) {
      var _this = this
      let obj = {
        // 采购信息表
        enterprise_info: {
          enterprise_legal_person : {}
        }
      }
      $.ajax({
        url: DomainName + '/getSubtableInquiryOriginal',
        type: 'POST',
        data: {
          Primary_Key: Enterprise_Info_SerialNumber,
          JSONObject: JSON.stringify(obj),
          token: $.cookie("token")
        },
        success: function (result) {
          console.log(result)
          _this.form = result.enterprise_info[0]
        },
        error: function (params) {
          console.log(params);
        },
      })
    },
    submit() {
      var _this = this
      console.log(this.form1)
      this.loading = true
      if (_this.loading) {
        $.ajax({
          url: DomainName + '/getAddAction',
          type: 'POST',
          data: { Data: JSON.stringify({ enterprise_account: [_this.form1] }), token: $.cookie("token") },
          success: function (result) {
            console.log(result)
            if (result.Status == 'success') {
              _this.$message('增加成功')
              _this.OddNumbers = false
              _this.getEnterpriseData()
            }
          },
          error: function (params) {
            console.log(params);
          },
          complete: function (XMLHttpRequest) {
            _this.loading = false
            if (XMLHttpRequest.getResponseHeader("REDIRECT") == "REDIRECT") {
              window.parent.document.location.href = "../../../" + XMLHttpRequest.getResponseHeader("CONTENTPATH");
            }
          }
        })
      }
    },
    uploadFront(file) {
      let _this = this
      let num = 1
      if (file.size > 150000 && file.size < 500000) {
        num = 0.4
      } else if (file.size > 500000) {
        num = 0.2
      }
      new Compressor(file, {
        quality: num,
        // if(file.size) {
        // }
        success(file) {
          console.log(file.size)
          const formData = new FormData();
          formData.append('file', file, file.name);
          let oFileReader = new FileReader();
          oFileReader.readAsDataURL(file);
          oFileReader.onload = function (e) {
            $.ajax({
              type: 'POST',
              url: DomainName + '/FileList',
              data: {
                Data: e.target.result,
                DataLength: file.size,
                FileName: file.name
              },
              complete: function (XMLHttpRequest) {
                _this.loading = false
                if (XMLHttpRequest.getResponseHeader("REDIRECT") == "REDIRECT") {
                  window.parent.document.location.href = "../../../" + XMLHttpRequest.getResponseHeader("CONTENTPATH");
                }
              },
              success: function (Result) {
                _this.tableData1.Picture_URL = e.target.result
                if (Result.Status == "success") {
                  _this.tableData1.Picture_URL = Result.Picture_Url
                  _this.$message.success('上传成功')
                  console.log(Result.Picture_Url);
                } else {
                  _this.$message.error('上传失败')
                }
              },
              error: function () {
                _this.$message.error("操作失败，请稍后再试")
              },
              dataType: "json"
            });
          }
        },
        error(err) {
          console.log(err.message);
        },
      });
    },
    handlePictureCardPreview(file) {
      this.dialogVisible = true
      this.dialogImageUrl = file
    },
    //删除图片
    handleRemove() {
      _this.tableData1.Picture_URL = ''
    },
  }
})